package springboot.study.project.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * @ClassName: PagingInfo
 * @Description: 用于分页的类
 * @Author: baoxia
 * @Date: 2020-07-08 23:28
 * @Version: 1.0
 **/
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class PagingInfo {
    /**
     * 当前要查询的页码
     */
    private Integer page;
    /**
     * 每页显示的记录数量
     */
    private Integer limit;
    /**
     * 起始索引
     */
    private Integer offset;

    /**
     * 构造函数
     *
     * @param page 当前要查询的页码
     * @param limit 每页显示的记录数量
     */
    public PagingInfo(Integer page, Integer limit) {
        this.page = page;
        this.limit = limit;
        this.offset = (page - 1) * limit;
    }

    /**
     * 获取起始索引
     * @return 起始索引
     */
    public Integer getOffset() {
        offset = (page - 1) * limit;
        return offset;
    }
}
